# -*- coding: utf-8 -*-

import sys
sys.path.append('/opt/alps/lib')
sys.path.append('/share/opt/alps/lib')
import pyalps
import matplotlib.pyplot as plt
import pyalps.plot
import numpy as np
import time
import multiprocessing

#----------------------1 Run the Task-------------------

rho = 2
numcores = 5
Ls = [8,16,32]
N_totals = [0,1,2]
Omegas = np.arange(0,0.3,0.1)
Paras = []
for i in Ls:
    for j in N_totals:
        for k in Omegas:
            Paras.append((i,j,k))

def Runmps(para):
    (L,N_total,Omega) = para
    BHparm = {}
    BHparm['LATTICE_LIBRARY'] = "0lattices.xml"
    BHparm['LATTICE'] = "inhomogeneous open chain lattice"
    BHparm['MODEL_LIBRARY'] = "0models.xml"
    BHparm['MODEL'] = "boson Hubbard with STMC U0 U2"

    BHparm['L'] = L
    BHparm['CONSERVED_QUANTUMNUMBERS'] = 'N'
    BHparm['N_total'] = N_total
    BHparm['COMPLEX'] = 1
    BHparm['t'] = 0.10
    BHparm['Omega'] = Omega
    BHparm['phi'] = 'Pi*2/3'
    BHparm['U0'] = 1
    BHparm['U2'] = 0

    BHparm['Nmax'] = 2
    BHparm['SWEEPS'] = 20
    BHparm['MAXSTATES'] = 120

#    BHparm['MEASURE_CORRELATIONS[Splus_Splus_Splus_Splus_correlations]'] ='SplusSplus'

    BHparm = [BHparm]
    input_file = pyalps.writeInputFiles('N_1_L=' + str(para), BHparm)
    a1 = time.time()
    pyalps.runApplication('mps_optim', input_file)
    a2 = time.time()
    print('run %s task has spent %.2f minutes' % (para, (a2 - a1)/60.0))

pool = multiprocessing.Pool(processes=numcores)
pool.map(Runmps, Paras)
pool.close()
pool.join()



#----------------------2 data_analysis--------------------------
##  still empty
